package com.elvin.activitylifecycle;

import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.os.Build;

public class MainActivity extends Activity {

	private final String TAG = "Activity";
	
	private Button btnStartAty1;
	private TextView tvOut;
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Log.i(TAG,"-->onCreate");
        
        tvOut = (TextView)findViewById(R.id.tvOut);
        
        btnStartAty1 = (Button)findViewById(R.id.btnStartAty1);
        
        btnStartAty1.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent i = new Intent(MainActivity.this, Aty1.class);
				
				//传入下个Activity的值，key-value单个值
				//i.putExtra("txt","Hello Aty1");
				
				//传递较为复杂的数据方式是Bundle
				Bundle data = new Bundle();
				data.putString("txt", "Hello Aty1");
				i.putExtras(data);
				
				//直接打开下个一Activity
				//startActivity(i);	
				
				//带有返回结果的启动下一个Activity，0表示返回当前Activity会执行onActivityResult方法
				startActivityForResult(i, 0);
				
			}
		});
    }
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    	// TODO Auto-generated method stub
    	String result = data.getStringExtra("res");
    	tvOut.setText(result);
    	
    	
    	super.onActivityResult(requestCode, resultCode, data);
    }
    
    @Override
    protected void onStart() {
    	// TODO Auto-generated method stub
    	super.onStart();
    	Log.i(TAG,"-->onStart");
    }
    
    @Override
    protected void onResume() {
    	// TODO Auto-generated method stub
    	super.onResume();
    	Log.i(TAG,"-->onResume");
    }
    
    @Override
    protected void onPause() {
    	// TODO Auto-generated method stub
    	super.onPause();
    	Log.i(TAG,"-->onPause");
    }
    
    @Override
    protected void onStop() {
    	// TODO Auto-generated method stub
    	super.onStop();
    	Log.i(TAG,"-->onStop");
    }
    
    @Override
    protected void onRestart() {
    	// TODO Auto-generated method stub
    	super.onRestart();
    	Log.i(TAG,"-->onRestart");
    }
    
    @Override
    protected void onDestroy() {
    	// TODO Auto-generated method stub
    	super.onDestroy();
    	Log.i(TAG,"-->onDestroy");
    }

}
